/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.RightCommand;
/*    */ import com.zimbra.cs.account.accesscontrol.RightModifier;
/*    */ import com.zimbra.soap.JaxbUtil;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.message.GrantRightRequest;
/*    */ import com.zimbra.soap.admin.type.RightModifierInfo;
/*    */ import com.zimbra.soap.type.ZmBoolean;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GrantRight
/*    */   extends RightDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 39 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 41 */     GrantRightRequest grReq = (GrantRightRequest)JaxbUtil.elementToJaxb(request);
/* 42 */     RightModifierInfo modifierInfo = grReq.getRight();
/* 43 */     if (modifierInfo == null) {
/* 44 */       throw ServiceException.INVALID_REQUEST("No information specified on what right to assign", null);
/*    */     }
/* 46 */     RightModifier rightModifier = getRightModifier(modifierInfo);
/*    */     
/*    */ 
/*    */ 
/* 50 */     RightCommand.grantRight(Provisioning.getInstance(), getAuthenticatedAccount(zsc), grReq.getTarget(), grReq.getGrantee(), modifierInfo.getValue(), rightModifier);
/*    */     
/*    */ 
/* 53 */     Element response = zsc.createElement(AdminConstants.GRANT_RIGHT_RESPONSE);
/* 54 */     return response;
/*    */   }
/*    */   
/*    */   static RightModifier getRightModifier(RightModifierInfo eRight) throws ServiceException {
/* 58 */     boolean deny = ZmBoolean.toBool(eRight.getDeny(), false);
/* 59 */     boolean canDelegate = ZmBoolean.toBool(eRight.getCanDelegate(), false);
/* 60 */     boolean disinheritSubGroups = ZmBoolean.toBool(eRight.getDisinheritSubGroups(), false);
/* 61 */     boolean subDomain = ZmBoolean.toBool(eRight.getSubDomain(), false);
/*    */     
/* 63 */     int numModifiers = 0;
/* 64 */     if (deny) {
/* 65 */       numModifiers++;
/*    */     }
/* 67 */     if (canDelegate) {
/* 68 */       numModifiers++;
/*    */     }
/* 70 */     if (disinheritSubGroups) {
/* 71 */       numModifiers++;
/*    */     }
/* 73 */     if (subDomain) {
/* 74 */       numModifiers++;
/*    */     }
/*    */     
/* 77 */     if (numModifiers > 1) {
/* 78 */       throw ServiceException.INVALID_REQUEST("can only have one modifier", null);
/*    */     }
/*    */     
/* 81 */     RightModifier rightModifier = null;
/* 82 */     if (deny) {
/* 83 */       rightModifier = RightModifier.RM_DENY;
/* 84 */     } else if (canDelegate) {
/* 85 */       rightModifier = RightModifier.RM_CAN_DELEGATE;
/* 86 */     } else if (disinheritSubGroups) {
/* 87 */       rightModifier = RightModifier.RM_DISINHERIT_SUB_GROUPS;
/* 88 */     } else if (subDomain) {
/* 89 */       rightModifier = RightModifier.RM_SUBDOMAIN;
/*    */     }
/* 91 */     return rightModifier;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 96 */     notes.add("Grantor must have the same or more rights on the same target or on a larger target set.");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GrantRight.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */